import json

from django.http import HttpResponse
from django.shortcuts import render, render_to_response
from PolicyData.PolicyControl import policy as policy_class
from Common import sql_content
from PublicChartDisplay.chartDisplayControl.user import area as area_class, salary as salary_class, area_map, analysis, demo_mag, \
    undefined_4
from ReckonJob.ReckonJobControl import selectJob
from Common import Fession_mini
# Create your views here.


def reckon(request):
    return render_to_response('reckonjob_first.html')

def get_job_position(request):
    #!---paging setting---!
    page_size = 20
    now_page = 1
    page_begin = 1
    page_end = 20
    end_page_begin = 0
    page_count = 1
    #!---data setting---!
    data_count = 0
    allJobNow = []
    if request.method == "GET":
        print('this is GET!')
        oldCondition = Fession_mini.getFessionMini('selectJob')
        if request.GET.get('key') is not None:
            print("asfesadfasdsdaf！", request.GET.get('key'))
            if request.GET.get('key') == "paging":
                now_page = int(request.GET.get('value'))
                allJobNow, data_count = selectJob._SelectJob().SelectJob_main()

            elif request.GET.get('key') == "directSearch":

                Fession_mini.setFessionMini('directSearch', request.GET.get('value'))
                allJobNow, data_count = selectJob._SelectJob().SelectJob_main(1)

            else:
                oldCondition[request.GET.get('key')] = request.GET.get('value')
                Fession_mini.setFessionMini('selectJob', oldCondition)
                allJobNow, data_count = selectJob._SelectJob().SelectJob_main()
        if (data_count % page_size == 0):
            page_count = data_count // page_size
        else:
            page_count = data_count // page_size + 1
            end_page_begin = data_count // page_size * page_size + 1
            # print(page_count,end_page_begin)
        if (request.GET.get('key') == "paging"):
            page_end = now_page * page_size
            page_begin = page_end - page_size + 1
            if (page_end > data_count):
                page_end = data_count
        #全部页码组成的列表
        page_count_list = []
        for num in range(1, page_count + 1):
            page_count_list.append(num)
        # # 设置页码最小值
        # if len(allJobNow) < page_end:
        #     page_end = len(allJobNow)
        # elif len(allJobNow) >= page_end:
        #     page_end = 30
        analysis_fill = allJobNow[page_begin : page_end]

        page_meg = {'page_count':page_count , 'page_count_list':page_count_list,'now_page':now_page}
        print('views_analysis_fill_modth', analysis_fill)
        this_data = {'Analysis': analysis_fill,'page_meg':page_meg}

        return HttpResponse(json.dumps(this_data))

    elif request.method == "POST":
        pass
def toDetail(request):
    now_id = int(request.GET.get('hidDetail'))
    if (now_id is not None):
        detail_fill = analysis._Analysis().analysis_sql_id(now_id)
        return render_to_response('analysis_allData_demo.html', {'detail_fill': detail_fill})